package com.hz.module.system.service.check.content;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.hz.module.system.controller.admin.check.content.vo.*;
import com.hz.module.system.dal.dataobject.check.content.CheckContentDO;
import com.hz.framework.common.pojo.PageResult;
import com.hz.framework.common.pojo.PageParam;
import com.hz.framework.common.util.object.BeanUtils;

import com.hz.module.system.dal.mysql.check.content.CheckContentMapper;

import static com.hz.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.hz.module.system.enums.ErrorCodeConstants.*;

/**
 * 检查内容清单 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class CheckContentServiceImpl implements CheckContentService {

    @Resource
    private CheckContentMapper checkContentMapper;

    @Override
    public String createCheckContent(CheckContentSaveReqVO createReqVO) {
        // 插入
        CheckContentDO checkContent = BeanUtils.toBean(createReqVO, CheckContentDO.class);
        checkContentMapper.insert(checkContent);
        // 返回
        return checkContent.getId();
    }

    @Override
    public void updateCheckContent(CheckContentSaveReqVO updateReqVO) {
        // 校验存在
        validateCheckContentExists(updateReqVO.getId());
        // 更新
        CheckContentDO updateObj = BeanUtils.toBean(updateReqVO, CheckContentDO.class);
        checkContentMapper.updateById(updateObj);
    }

    @Override
    public void deleteCheckContent(String id) {
        // 校验存在
        validateCheckContentExists(id);
        // 删除
        checkContentMapper.deleteById(id);
    }

    private void validateCheckContentExists(String id) {
        if (checkContentMapper.selectById(id) == null) {
            throw exception(CHECK_CONTENT_NOT_EXISTS);
        }
    }

    @Override
    public CheckContentDO getCheckContent(String id) {
        return checkContentMapper.selectById(id);
    }

    @Override
    public PageResult<CheckContentDO> getCheckContentPage(CheckContentPageReqVO pageReqVO) {
        return checkContentMapper.selectPage(pageReqVO);
    }

}